Trò chơi đua xe động vật trong UNITY Engine
114.690 lượt xem;
- SpatialInfo.cs
- Spriter /
- Editor /
- Spriter2Unity /
- ThirdParty /
- Assets /
- project /
1 /*
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using UnityEngine;
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using System.Xml;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class SpatialInfo
33 {
34 public Vector2 Position { get; private set; }
35 public Vector2 Scale { get; private set; }
36 public float Angle_Deg { get; private set; }
37 public float Angle
38 {
39 get
40 {
41 return Mathf.Deg2Rad * Angle_Deg;
42 }
43 }
44 public SpinDirection Spin { get; private set; }
45
46 public SpatialInfo(XmlElement element)
47 {
48 Parse(element);
49 }
50
51 private SpatialInfo()
52 { }
53
54 public SpatialInfo Unmap(SpatialInfo parent)
55 {
56 if (parent == null)
57 return this;
58
59 var unmapped = new SpatialInfo();
60
61 unmapped.Position = new Vector2(
62 Position.x * parent.Scale.x,
63 Position.y * parent.Scale.y);
64 unmapped.Scale = new Vector2(
65 Scale.x * parent.Scale.x,
66 Scale.y * parent.Scale.y);
67 unmapped.Angle_Deg = Angle_Deg;
68
69 if (parent.Scale.x * parent.Scale.y < 0)
70 {
71 unmapped.Angle_Deg = 360 - unmapped.Angle_Deg;
72 }
73
74 unmapped.Spin = Spin;
75
76 return unmapped;
77 }
78
79 protected virtual void Parse(XmlElement element)
80 {
81 Vector2 position;
82 position.x = element.GetFloat("x", 0.0f);
83 position.y = element.GetFloat("y", 0.0f);
84 Position = position;
85
86 Vector2 scale = Vector2.one;
87 scale.x = element.GetFloat("scale_x", 1.0f);
88 scale.y = element.GetFloat("scale_y", 1.0f);
89 Scale = scale;
90
91 Angle_Deg = element.GetFloat("angle", 0.0f);
92
93 int spinVal = element.GetInt("spin", 1);
94 Spin = (spinVal == -1) ? SpinDirection.Clockwise : SpinDirection.CounterClockwise;
95 }
96 }
97 }
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using UnityEngine;
24 using System;
25 using System.Collections.Generic;
26 using System.Linq;
27 using System.Text;
28 using System.Xml;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class SpatialInfo
33 {
34 public Vector2 Position { get; private set; }
35 public Vector2 Scale { get; private set; }
36 public float Angle_Deg { get; private set; }
37 public float Angle
38 {
39 get
40 {
41 return Mathf.Deg2Rad * Angle_Deg;
42 }
43 }
44 public SpinDirection Spin { get; private set; }
45
46 public SpatialInfo(XmlElement element)
47 {
48 Parse(element);
49 }
50
51 private SpatialInfo()
52 { }
53
54 public SpatialInfo Unmap(SpatialInfo parent)
55 {
56 if (parent == null)
57 return this;
58
59 var unmapped = new SpatialInfo();
60
61 unmapped.Position = new Vector2(
62 Position.x * parent.Scale.x,
63 Position.y * parent.Scale.y);
64 unmapped.Scale = new Vector2(
65 Scale.x * parent.Scale.x,
66 Scale.y * parent.Scale.y);
67 unmapped.Angle_Deg = Angle_Deg;
68
69 if (parent.Scale.x * parent.Scale.y < 0)
70 {
71 unmapped.Angle_Deg = 360 - unmapped.Angle_Deg;
72 }
73
74 unmapped.Spin = Spin;
75
76 return unmapped;
77 }
78
79 protected virtual void Parse(XmlElement element)
80 {
81 Vector2 position;
82 position.x = element.GetFloat("x", 0.0f);
83 position.y = element.GetFloat("y", 0.0f);
84 Position = position;
85
86 Vector2 scale = Vector2.one;
87 scale.x = element.GetFloat("scale_x", 1.0f);
88 scale.y = element.GetFloat("scale_y", 1.0f);
89 Scale = scale;
90
91 Angle_Deg = element.GetFloat("angle", 0.0f);
92
93 int spinVal = element.GetInt("spin", 1);
94 Spin = (spinVal == -1) ? SpinDirection.Clockwise : SpinDirection.CounterClockwise;
95 }
96 }
97 }